﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;

[Serializable]
public class AbstractData
{

    public const string IDField = "@ID";

    public const string PRIMARYKEY_Field = @"ID";

    public const string EMAILField = "@Email";

    public const string TITLEField = "@Title";

    public const string AUTHORField = "@Author";

    public const string COMMEMAILField = "@CommEmail";

    public const string KEY_WORDSField = "@Key_Words";

    public const string ABSTRACTField = "@Abstract";

    public const string SESSIONField = "@Session";

    private Int32 _ID;

    private String _Email;

    private String _Title;

    private String _Author;

    private String _CommEmail;

    private String _Key_Words;

    private String _Abstract;

    private String _Session;

    public Int32 ID
    {
        get { return _ID; }
        set { _ID = value; }
    }
    public String Email
    {
        get { return _Email; }
        set { _Email = value; }
    }
    public String Title
    {
        get { return _Title; }
        set { _Title = value; }
    }
    public String Author
    {
        get { return _Author; }
        set { _Author = value; }
    }
    public String CommEmail
    {
        get { return _CommEmail; }
        set { _CommEmail = value; }
    }
    public String Key_Words
    {
        get { return _Key_Words; }
        set { _Key_Words = value; }
    }
    public String Abstract
    {
        get { return _Abstract; }
        set { _Abstract = value; }
    }
    public String Session
    {
        get { return _Session; }
        set { _Session = value; }
    }
    public AbstractData()
    {
        _ID = 0;
        _Email = "";
        _Title = "";
        _Author = "";
        _CommEmail = "";
        _Key_Words = "";
        _Abstract = "";
        _Session = "";
    }
}

public class AbstractDataFactory
{
    public static AbstractData Construct(IDataReader reader)
    {
        AbstractData data = new AbstractData();

        try { data.ID = Convert.ToInt32(reader["ID"]); }
        catch { }

        try { data.Email = Convert.ToString(reader["Email"]); }
        catch { }

        try { data.Title = Convert.ToString(reader["Title"]); }
        catch { }

        try { data.Author = Convert.ToString(reader["Author"]); }
        catch { }

        try { data.CommEmail = Convert.ToString(reader["CommEmail"]); }
        catch { }

        try { data.Key_Words = Convert.ToString(reader["Key_Words"]); }
        catch { }

        try { data.Abstract = Convert.ToString(reader["Abstract"]); }
        catch { }

        try { data.Session = Convert.ToString(reader["Session"]); }
        catch { }

        return data;
    }
    public static Int32 GetPrimaryKey(DataTable dt)
    {
        return GetPrimaryKey(dt, 0);
    }
    public static Int32 GetPrimaryKey(DataTable dt, int rowIndex)
    {
        Int32 PrimaryKey = 0;

        if (dt.Rows.Count < rowIndex + 1)

            return 0;

        DataRow dr = dt.Rows[rowIndex];

        if (dr == null)

            return 0;

        try { PrimaryKey = Convert.ToInt32(dr[AbstractData.PRIMARYKEY_Field]); }
        catch { }

        return PrimaryKey;
    }
    public static AbstractData Construct(DataTable dt)
    {
        return Construct(dt, 0);
    }
    public static AbstractData Construct(DataTable dt, int rowIndex)
    {
        AbstractData data = new AbstractData();

        if (dt.Rows.Count < rowIndex + 1)

            return null;

        DataRow dr = dt.Rows[rowIndex];

        if (dr == null)

            return null;

        try { data.ID = Convert.ToInt32(dr["ID"]); }
        catch { }

        try { data.Email = Convert.ToString(dr["Email"]); }
        catch { }

        try { data.Title = Convert.ToString(dr["Title"]); }
        catch { }

        try { data.Author = Convert.ToString(dr["Author"]); }
        catch { }

        try { data.CommEmail = Convert.ToString(dr["CommEmail"]); }
        catch { }

        try { data.Key_Words = Convert.ToString(dr["Key_Words"]); }
        catch { }

        try { data.Abstract = Convert.ToString(dr["Abstract"]); }
        catch { }

        try { data.Session = Convert.ToString(dr["Session"]); }
        catch { }

        return data;
    }    
    public static AbstractData Construct(DataRow dr)
    {
        AbstractData data = new AbstractData();

        try { data.ID = Convert.ToInt32(dr["ID"]); }
        catch { }

        try { data.Email = Convert.ToString(dr["Email"]); }
        catch { }

        try { data.Title = Convert.ToString(dr["Title"]); }
        catch { }

        try { data.Author = Convert.ToString(dr["Author"]); }
        catch { }

        try { data.CommEmail = Convert.ToString(dr["CommEmail"]); }
        catch { }

        try { data.Key_Words = Convert.ToString(dr["Key_Words"]); }
        catch { }

        try { data.Abstract = Convert.ToString(dr["Abstract"]); }
        catch { }

        try { data.Session = Convert.ToString(dr["Session"]); }
        catch { }

        return data;
    }
    public static Int32 GetPrimaryKey(DataRow dr)
    {
        Int32 PrimaryKey = 0;

        try { PrimaryKey = Convert.ToInt32(dr[AbstractData.PRIMARYKEY_Field]); }
        catch { }
        return PrimaryKey;
    }

}
public class AbstractDataDBOption
{
    public static int Insert(AbstractData d)
    {
        StringBuilder sql = new StringBuilder();
        sql.Append("insert into Abstract (");
        sql.Append("Email, ");
        sql.Append("Title, ");
        sql.Append("Author, ");
        sql.Append("CommEmail, ");
        sql.Append("Key_Words, ");
        sql.Append("Abstract, ");
        sql.Append("Session");
        sql.Append(") values (");
        sql.Append("'");
        sql.Append(d.Email.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.Title.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.Author.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.CommEmail.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.Key_Words.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.Abstract.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("'");
        sql.Append(d.Session.ToString());
        sql.Append("'");
        sql.Append(")");
        return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
    }
    public static int Update(AbstractData d)
    {
        StringBuilder sql = new StringBuilder();
        sql.Append("update Abstract set ");
        sql.Append("Email=");
        sql.Append("'");
        sql.Append(d.Email.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("Title=");
        sql.Append("'");
        sql.Append(d.Title.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("Author=");
        sql.Append("'");
        sql.Append(d.Author.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("CommEmail=");
        sql.Append("'");
        sql.Append(d.CommEmail.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("Key_Words=");
        sql.Append("'");
        sql.Append(d.Key_Words.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("Abstract=");
        sql.Append("'");
        sql.Append(d.Abstract.ToString());
        sql.Append("'");
        sql.Append(", ");
        sql.Append("Session=");
        sql.Append("'");
        sql.Append(d.Session.ToString());
        sql.Append("'");
        sql.Append(" where ID=");
        sql.Append(d.ID.ToString());
        return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
    }
    public static int Delete(AbstractData d)
    {
        StringBuilder sql = new StringBuilder();
        sql.Append("delete from Abstract ");
        sql.Append(" where ID=");
        sql.Append(d.ID.ToString());
        return WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql.ToString());
    }
    public static DataTable DataTableSelect(AbstractData d)
    {
        StringBuilder sql = new StringBuilder();
        sql.Append("select * from Abstract ");
        return WFNetLib.ADO.SQLServerOP.DataTableSQL(sql.ToString());
    }
    public static DataSet DataSetSelect(AbstractData d)
    {
        StringBuilder sql = new StringBuilder();
        sql.Append("select * from Abstract ");
        return WFNetLib.ADO.SQLServerOP.DataSetSQL(sql.ToString());
    }
    public static SqlDataReader ReaderSelect(AbstractData d)
    {
        StringBuilder sql = new StringBuilder();
        sql.Append("select * from Abstract ");
        return WFNetLib.ADO.SQLServerOP.ReaderExecuteSQL(sql.ToString());
    }
}